const express = require('express');
const router = express.Router();
const db = require('../utils/db');
var jwt = require('jsonwebtoken');



router.get('/getuser', function (req, res, next) {
  let mysql = `SELECT * FROM user WHERE user_id = ? AND user_password = ? AND  user_position= ?`
  db(mysql, [req.query.username, req.query.password, req.query.type], function (err, data) {
    if (err) {
      return res.json({
        code: 500,
        msg: '服务器报错，请稍后重试'
      })
    }
    res.json({
      code: 200,
      msg: '登录成功',
      data: data,
      token: jwt.sign({ data: data[0] }, 'web281', { expiresIn: '1h' })
    })

  })
});

module.exports = router